package cn.biplam.front.template.base;

import cn.biplam.common.tools.TOOLS;
import cn.biplam.common.wrapper.ErrorMessage;
import cn.biplam.front.html.HtmlDiv;
import cn.biplam.front.html.HtmlText;
import cn.biplam.front.html.base.HtmlWindow;
import cn.biplam.front.html.base.Const.Window_Event;

/**
 * 简要内容模版<br>
 * <ul>功能：
 * <li>显示内容的简要信息
 * <li>具有链接到内容详细信息窗口按钮
 * </ul>
 * @author XiaoRuxing 2009-7-3下午08:30:24
 * @version 1.0
 */
public class Tail {

	private HtmlDiv tail;
	/** 简要信息 */
	private String briefInfor;
	/** 页面ID */
	private String pageID;
	/** 连接动作脚本 */
	private String script;
	/** 控件显示所占字数 */
	private int length=0;
	
	/**
	 * 创建内容简介控件
	 * @param pageID     控件ID
	 * @param briefInfor 控件显示内容
	 * @param script     点击控件执行动作脚本
	 * @throws ErrorMessage 
	 */
	public Tail(String pageID,String briefInfor,String script) throws ErrorMessage{
		this.pageID = pageID;
		this.briefInfor = briefInfor;
		this.script = script;
		_init();
	}
	
	private void _init() throws ErrorMessage{
		this.tail = new HtmlDiv(this.pageID);
	}
	
	/**
	 * 获取简要信息界面
	 * @return
	 * @throws ErrorMessage
	 */
	public HtmlWindow get() throws ErrorMessage{
		HtmlWindow text = new Text(this.briefInfor).get();
		this.tail.put(text);
		if(!TOOLS.StringIsEmpty(this.briefInfor)){
			this.length=this.length+this.briefInfor.getBytes().length;
			HtmlText link=new HtmlText(null,"tipt","…");
			link.bind(Window_Event.OnClick,this.script);
			this.tail.put(link);
			this.length = this.length+3;
			tail.setLength(TOOLS.getPxLength(this.length));
		}
		return this.tail;
	}
	
	/**
	 * 获取控件占位字数
	 * @return
	 */
	public int getLength(){
		return this.length;
	}
}
